{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;height: 750px">


    <div class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">文章标题</label>
            <div class="layui-input-inline">
                <input type="hidden" name="id" value="{$info.id|default=''}">
                <input type="hidden" id="type" value="{$type|default=''}">
                <input type="text" name="title" value="{$info.title|default=''}" placeholder="请输入文章标题"  lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文章描述</label>
            <div class="layui-input-block">
                <input type="text" name="desc" value="{$info.desc|default=''}"  placeholder="请输入文章描述" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题图片</label>
            <div class="layui-input-inline">
                <div class="layui-upload-drag" id="upload_title">
                    <i class="layui-icon"></i>
                    <p>点击上传，或将文件拖拽到此处</p>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题图片</label>
            <div class="layui-input-inline">
                <div><img src="{$info.title_img|default=''}" class="title_img"></div>
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">内容图片</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<div class="layui-upload-drag" id="upload_content">-->
                    <!--<i class="layui-icon"></i>-->
                    <!--<p>点击上传，或将文件拖拽到此处</p>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">内容图片</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<div><img src="{$info.content_img|default=''}" class="content_img"></div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">原文章内容</label>
            <div class="layui-input-inline" style="width: 100%;height: 300px">
                <textarea id="demo" name="content" lay-verify="content">{$info.content|default=''}</textarea>
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 5rem">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </div>
    </div>


</div>
{include file='common/footer'}

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //
        // //日期
        // laydate.render({
        //     elem: '#date'
        // });
        // laydate.render({
        //     elem: '#date1'
        // });
        //
        // //创建一个编辑器
        layedit.set({
            uploadImage:{
                url:'{:url("admin/Upload/editUpload")}',
                type:'post'
            }
        });
        var editIndex = layedit.build('demo', {
                tool: [
                    'strong' //加粗
                    ,'italic' //斜体
                    ,'underline' //下划线
                    ,'del' //删除线

                    ,'|' //分割线

                    ,'left' //左对齐
                    ,'center' //居中对齐
                    ,'right' //右对齐
                    ,'image'
                ],
            });
        //
        //自定义验证规则
        form.verify({
            pass: []
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        // //监听指定开关
        // form.on('switch(switchTest)', function(data){
        //     layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        // });



        //监听提交
        var url='{:url("admin/News/newsModify")}';
        form.on('submit(demo1)', function(data){
            data.field.title_img = $('.title_img').attr('src');
            var type = $('#type').val();
            data.field['type'] = type;
            $.post(url,data.field,function (obj) {
                if(obj.code==200){
                    parent.layer.msg(obj.msg, {icon: 6,time: 1000});
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index,data.field); //再执行关闭
                }
                if(obj.code==400){
                    parent.layer.msg(obj.msg, {icon: 5,time: 1000});
                }
            },"JSON");
        });


    });
</script>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_title' //绑定元素
            ,url: '{:url("Upload/file_images")}' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    $('.title_img').attr('src',res.data.src)

                }
            }
            ,accept: ''
            ,error: function(res){
                //请求异常回调
                console.log(res)
            }
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_content' //绑定元素
            ,url: '{:url("Upload/file_images")}' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    $('.content_img').attr('src',res.data.src)

                }
            }
            ,accept: ''
            ,error: function(res){
                //请求异常回调
                console.log(res)
            }
        });
    });
</script>
</body>
</html>